package com.zygh.policeasset.service;

import com.zygh.policeasset.mapper.MenuMapper;
import com.zygh.policeasset.mapper.UserMapper;
import com.zygh.policeasset.pojo.Menu;
import com.zygh.policeasset.pojo.User;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/MenuService.class */
public class MenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private UserMapper userMapper;

    public User findMenuByUserId(String username) {
        return this.userMapper.findByUsername(username);
    }

    public List<Menu> findAllMenu() {
        List<Menu> MenuList = this.menuMapper.findMenuByParentId(null);
        List<Menu> root = new ArrayList<>();
        for (Menu item : MenuList) {
            if (item.getParentId() == 0) {
                root.add(item);
            }
        }
        for (Menu menu : root) {
            menu.setChildren(getChild(menu.getId(), MenuList));
        }
        return root;
    }

    public List<Menu> getChild(int id, List<Menu> all) {
        List<Menu> childList = new ArrayList<>();
        for (Menu menu : all) {
            if (menu.getParentId() == id) {
                childList.add(menu);
            }
        }
        for (Menu item : childList) {
            item.setChildren(getChild(item.getId(), all));
        }
        if (childList.size() == 0) {
            return new ArrayList();
        }
        return childList;
    }

    public Integer addMenu(Menu menu) {
        return this.menuMapper.addMenu(menu);
    }

    public Integer deleteMenu(int id) {
        return this.menuMapper.deleteMenu(id);
    }

    public Integer updateMenu(Menu menu) {
        return this.menuMapper.updateMenu(menu);
    }

    public List<Menu> findParent(int parentId) {
        return this.menuMapper.findParent(parentId);
    }
}